.class public final Lcom/burstly/lib/service/SdCardWatchingService;
.super Ljava/lang/Object;
.source "SdCardWatchingService.java"


# annotations
.annotation system Ldalvik/annotation/MemberClasses;
    value = {
        Lcom/burstly/lib/service/SdCardWatchingService$IWatcherNotificator;
    }
.end annotation


# static fields
.field private static final LISTENERS:Ljava/util/List; = null
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "Ljava/util/List",
            "<",
            "Lcom/burstly/lib/service/SdCardWatchingService$IWatcherNotificator;",
            ">;"
        }
    .end annotation
.end field

.field private static final LOG:Lcom/burstly/lib/util/LoggerExt; = null

.field private static final TAG:Ljava/lang/String; = "SdCardWatchingService"

.field private static sInstance:Lcom/burstly/lib/service/SdCardWatchingService;


# instance fields
.field private final mApplicationContext:Landroid/content/Context;

.field private mExternalStorageReceiver:Landroid/content/BroadcastReceiver;

.field mExternalStorageUsable:Z


# direct methods
.method static constructor <clinit>()V
    .locals 1

    .prologue
    .line 38
    invoke-static {}, Lcom/burstly/lib/util/LoggerExt;->getInstance()Lcom/burstly/lib/util/LoggerExt;

    move-result-object v0

    sput-object v0, Lcom/burstly/lib/service/SdCardWatchingService;->LOG:Lcom/burstly/lib/util/LoggerExt;

    .line 68
    new-instance v0, Ljava/util/ArrayList;

    invoke-direct {v0}, Ljava/util/ArrayList;-><init>()V

    sput-object v0, Lcom/burstly/lib/service/SdCardWatchingService;->LISTENERS:Ljava/util/List;

    return-void
.end method

.method private constructor <init>(Landroid/content/Context;)V
    .locals 1
    .parameter "ctxt"

    .prologue
    .line 75
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 53
    const/4 v0, 0x0

    iput-boolean v0, p0, Lcom/burstly/lib/service/SdCardWatchingService;->mExternalStorageUsable:Z

    .line 76
    invoke-virtual {p1}, Landroid/content/Context;->getApplicationContext()Landroid/content/Context;

    move-result-object v0

    iput-object v0, p0, Lcom/burstly/lib/service/SdCardWatchingService;->mApplicationContext:Landroid/content/Context;

    .line 77
    invoke-direct {p0}, Lcom/burstly/lib/service/SdCardWatchingService;->startWatchingExternalStorage()V

    .line 78
    return-void
.end method

.method static synthetic access$000()Lcom/burstly/lib/util/LoggerExt;
    .locals 1

    .prologue
    .line 34
    sget-object v0, Lcom/burstly/lib/service/SdCardWatchingService;->LOG:Lcom/burstly/lib/util/LoggerExt;

    return-object v0
.end method

.method public static addNotificationListener(Lcom/burstly/lib/service/SdCardWatchingService$IWatcherNotificator;)V
    .locals 4
    .parameter "notificationListener"

    .prologue
    .line 136
    if-eqz p0, :cond_0

    .line 137
    sget-object v0, Lcom/burstly/lib/service/SdCardWatchingService;->LISTENERS:Ljava/util/List;

    invoke-interface {v0, p0}, Ljava/util/List;->add(Ljava/lang/Object;)Z

    .line 141
    :goto_0
    return-void

    .line 139
    :cond_0
    sget-object v0, Lcom/burstly/lib/service/SdCardWatchingService;->LOG:Lcom/burstly/lib/util/LoggerExt;

    const-string v1, "SdCardWatchingService"

    const-string v2, "Notification listener is NULL. Can not add."

    const/4 v3, 0x0

    new-array v3, v3, [Ljava/lang/Object;

    invoke-virtual {v0, v1, v2, v3}, Lcom/burstly/lib/util/LoggerExt;->logError(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    goto :goto_0
.end method

.method private notifyListeners()V
    .locals 3

    .prologue
    .line 97
    sget-object v2, Lcom/burstly/lib/service/SdCardWatchingService;->LISTENERS:Ljava/util/List;

    invoke-interface {v2}, Ljava/util/List;->isEmpty()Z

    move-result v2

    if-nez v2, :cond_0

    .line 98
    sget-object v2, Lcom/burstly/lib/service/SdCardWatchingService;->LISTENERS:Ljava/util/List;

    invoke-interface {v2}, Ljava/util/List;->iterator()Ljava/util/Iterator;

    move-result-object v0

    .local v0, i$:Ljava/util/Iterator;
    :goto_0
    invoke-interface {v0}, Ljava/util/Iterator;->hasNext()Z

    move-result v2

    if-eqz v2, :cond_0

    invoke-interface {v0}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v1

    check-cast v1, Lcom/burstly/lib/service/SdCardWatchingService$IWatcherNotificator;

    .line 99
    .local v1, listener:Lcom/burstly/lib/service/SdCardWatchingService$IWatcherNotificator;
    iget-boolean v2, p0, Lcom/burstly/lib/service/SdCardWatchingService;->mExternalStorageUsable:Z

    invoke-interface {v1, v2}, Lcom/burstly/lib/service/SdCardWatchingService$IWatcherNotificator;->notifySdCardStateChanged(Z)V

    goto :goto_0

    .line 102
    .end local v0           #i$:Ljava/util/Iterator;
    .end local v1           #listener:Lcom/burstly/lib/service/SdCardWatchingService$IWatcherNotificator;
    :cond_0
    return-void
.end method

.method public static removeNotificationListener(Lcom/burstly/lib/service/SdCardWatchingService$IWatcherNotificator;)V
    .locals 4
    .parameter "notificationListener"

    .prologue
    .line 149
    if-eqz p0, :cond_0

    .line 150
    sget-object v0, Lcom/burstly/lib/service/SdCardWatchingService;->LISTENERS:Ljava/util/List;

    invoke-interface {v0, p0}, Ljava/util/List;->remove(Ljava/lang/Object;)Z

    .line 154
    :goto_0
    return-void

    .line 152
    :cond_0
    sget-object v0, Lcom/burstly/lib/service/SdCardWatchingService;->LOG:Lcom/burstly/lib/util/LoggerExt;

    const-string v1, "SdCardWatchingService"

    const-string v2, "Notification listener is NULL. Can not remove."

    const/4 v3, 0x0

    new-array v3, v3, [Ljava/lang/Object;

    invoke-virtual {v0, v1, v2, v3}, Lcom/burstly/lib/util/LoggerExt;->logError(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    goto :goto_0
.end method

.method public static declared-synchronized startWatching(Landroid/content/Context;)V
    .locals 5
    .parameter "ctxt"

    .prologue
    .line 164
    const-class v1, Lcom/burstly/lib/service/SdCardWatchingService;

    monitor-enter v1

    :try_start_0
    sget-object v0, Lcom/burstly/lib/service/SdCardWatchingService;->sInstance:Lcom/burstly/lib/service/SdCardWatchingService;

    if-nez v0, :cond_0

    .line 165
    sget-object v0, Lcom/burstly/lib/service/SdCardWatchingService;->LOG:Lcom/burstly/lib/util/LoggerExt;

    const-string v2, "SdCardWatchingService"

    const-string v3, "Start watching after SD card state."

    const/4 v4, 0x0

    new-array v4, v4, [Ljava/lang/Object;

    invoke-virtual {v0, v2, v3, v4}, Lcom/burstly/lib/util/LoggerExt;->logDebug(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    .line 166
    new-instance v0, Lcom/burstly/lib/service/SdCardWatchingService;

    invoke-direct {v0, p0}, Lcom/burstly/lib/service/SdCardWatchingService;-><init>(Landroid/content/Context;)V

    sput-object v0, Lcom/burstly/lib/service/SdCardWatchingService;->sInstance:Lcom/burstly/lib/service/SdCardWatchingService;
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0

    .line 170
    :goto_0
    monitor-exit v1

    return-void

    .line 168
    :cond_0
    :try_start_1
    sget-object v0, Lcom/burstly/lib/service/SdCardWatchingService;->LOG:Lcom/burstly/lib/util/LoggerExt;

    const-string v2, "SdCardWatchingService"

    const-string v3, "Watching is in progress. Ok."

    const/4 v4, 0x0

    new-array v4, v4, [Ljava/lang/Object;

    invoke-virtual {v0, v2, v3, v4}, Lcom/burstly/lib/util/LoggerExt;->logDebug(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;
    :try_end_1
    .catchall {:try_start_1 .. :try_end_1} :catchall_0

    goto :goto_0

    .line 164
    :catchall_0
    move-exception v0

    monitor-exit v1

    throw v0
.end method

.method private startWatchingExternalStorage()V
    .locals 4

    .prologue
    .line 108
    new-instance v1, Lcom/burstly/lib/service/SdCardWatchingService$1;

    invoke-direct {v1, p0}, Lcom/burstly/lib/service/SdCardWatchingService$1;-><init>(Lcom/burstly/lib/service/SdCardWatchingService;)V

    iput-object v1, p0, Lcom/burstly/lib/service/SdCardWatchingService;->mExternalStorageReceiver:Landroid/content/BroadcastReceiver;

    .line 115
    new-instance v0, Landroid/content/IntentFilter;

    invoke-direct {v0}, Landroid/content/IntentFilter;-><init>()V

    .line 116
    .local v0, filter:Landroid/content/IntentFilter;
    const-string v1, "file"

    invoke-virtual {v0, v1}, Landroid/content/IntentFilter;->addDataScheme(Ljava/lang/String;)V

    .line 117
    const-string v1, "android.intent.action.MEDIA_MOUNTED"

    invoke-virtual {v0, v1}, Landroid/content/IntentFilter;->addAction(Ljava/lang/String;)V

    .line 118
    const-string v1, "android.intent.action.MEDIA_UNMOUNTED"

    invoke-virtual {v0, v1}, Landroid/content/IntentFilter;->addAction(Ljava/lang/String;)V

    .line 119
    iget-object v1, p0, Lcom/burstly/lib/service/SdCardWatchingService;->mApplicationContext:Landroid/content/Context;

    iget-object v2, p0, Lcom/burstly/lib/service/SdCardWatchingService;->mExternalStorageReceiver:Landroid/content/BroadcastReceiver;

    new-instance v3, Landroid/content/IntentFilter;

    invoke-direct {v3, v0}, Landroid/content/IntentFilter;-><init>(Landroid/content/IntentFilter;)V

    invoke-virtual {v1, v2, v3}, Landroid/content/Context;->registerReceiver(Landroid/content/BroadcastReceiver;Landroid/content/IntentFilter;)Landroid/content/Intent;

    .line 120
    invoke-virtual {p0}, Lcom/burstly/lib/service/SdCardWatchingService;->updateExternalStorageState()V

    .line 121
    return-void
.end method

.method public static declared-synchronized stopWatching()V
    .locals 5

    .prologue
    .line 179
    const-class v1, Lcom/burstly/lib/service/SdCardWatchingService;

    monitor-enter v1

    :try_start_0
    sget-object v0, Lcom/burstly/lib/service/SdCardWatchingService;->sInstance:Lcom/burstly/lib/service/SdCardWatchingService;

    if-eqz v0, :cond_0

    .line 180
    sget-object v0, Lcom/burstly/lib/service/SdCardWatchingService;->LOG:Lcom/burstly/lib/util/LoggerExt;

    const-string v2, "SdCardWatchingService"

    const-string v3, "Stop watching SD card status."

    const/4 v4, 0x0

    new-array v4, v4, [Ljava/lang/Object;

    invoke-virtual {v0, v2, v3, v4}, Lcom/burstly/lib/util/LoggerExt;->logDebug(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    .line 181
    sget-object v0, Lcom/burstly/lib/service/SdCardWatchingService;->sInstance:Lcom/burstly/lib/service/SdCardWatchingService;

    invoke-direct {v0}, Lcom/burstly/lib/service/SdCardWatchingService;->stopWatchingExternalStorage()V

    .line 182
    sget-object v0, Lcom/burstly/lib/service/SdCardWatchingService;->LISTENERS:Ljava/util/List;

    invoke-interface {v0}, Ljava/util/List;->clear()V

    .line 183
    const/4 v0, 0x0

    sput-object v0, Lcom/burstly/lib/service/SdCardWatchingService;->sInstance:Lcom/burstly/lib/service/SdCardWatchingService;
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0

    .line 187
    :goto_0
    monitor-exit v1

    return-void

    .line 185
    :cond_0
    :try_start_1
    sget-object v0, Lcom/burstly/lib/service/SdCardWatchingService;->LOG:Lcom/burstly/lib/util/LoggerExt;

    const-string v2, "SdCardWatchingService"

    const-string v3, "Watch has already been stopped. Skip call."

    const/4 v4, 0x0

    new-array v4, v4, [Ljava/lang/Object;

    invoke-virtual {v0, v2, v3, v4}, Lcom/burstly/lib/util/LoggerExt;->logDebug(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;
    :try_end_1
    .catchall {:try_start_1 .. :try_end_1} :catchall_0

    goto :goto_0

    .line 179
    :catchall_0
    move-exception v0

    monitor-exit v1

    throw v0
.end method

.method private stopWatchingExternalStorage()V
    .locals 2

    .prologue
    .line 127
    iget-object v0, p0, Lcom/burstly/lib/service/SdCardWatchingService;->mApplicationContext:Landroid/content/Context;

    iget-object v1, p0, Lcom/burstly/lib/service/SdCardWatchingService;->mExternalStorageReceiver:Landroid/content/BroadcastReceiver;

    invoke-virtual {v0, v1}, Landroid/content/Context;->unregisterReceiver(Landroid/content/BroadcastReceiver;)V

    .line 128
    return-void
.end method


# virtual methods
.method updateExternalStorageState()V
    .locals 4

    .prologue
    const/4 v2, 0x0

    .line 84
    invoke-static {}, Landroid/os/Environment;->getExternalStorageState()Ljava/lang/String;

    move-result-object v1

    .line 85
    .local v1, state:Ljava/lang/String;
    iput-boolean v2, p0, Lcom/burstly/lib/service/SdCardWatchingService;->mExternalStorageUsable:Z

    .line 86
    const-string v3, "mounted"

    invoke-virtual {v3, v1}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v3

    if-eqz v3, :cond_1

    .line 87
    invoke-static {}, Landroid/os/Environment;->getExternalStorageDirectory()Ljava/io/File;

    move-result-object v0

    .line 88
    .local v0, externalStorageDirectory:Ljava/io/File;
    invoke-virtual {v0}, Ljava/io/File;->canRead()Z

    move-result v3

    if-eqz v3, :cond_0

    invoke-virtual {v0}, Ljava/io/File;->canWrite()Z

    move-result v3

    if-eqz v3, :cond_0

    const/4 v2, 0x1

    :cond_0
    iput-boolean v2, p0, Lcom/burstly/lib/service/SdCardWatchingService;->mExternalStorageUsable:Z

    .line 90
    .end local v0           #externalStorageDirectory:Ljava/io/File;
    :cond_1
    invoke-direct {p0}, Lcom/burstly/lib/service/SdCardWatchingService;->notifyListeners()V

    .line 91
    return-void
.end method
